<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表单验证</title>

</head>
<body>
<form action="" onsubmit="return validate()" method="post">
    Number:<input type="text" name="num1" id="num1"/>
    <br>
    Repeat: <input type="text" name="num2" id="num2"/>
    <br>
    <input type="submit" value="Submit">
</form>
<script>
    function validate() {
        var n1 = document.getElementById("num1");
        var n2 = document.getElementById("num2");
        if (n1.value !==  "" && n2.value !== ""){
            if (n1.value === n2.value){
                return true;
            }
        }
        alert("输入两个值不相等，请重新输入！");
        return false;


    }
</script>
</body>
</html>
